// 布局信息
// import { hasIn } from 'lodash'
import * as types from '@/store/mutation-types'
import api from '@/tools/api.js'
import promise from '@/tools/promise'
import { SUCCESS_STATUS } from '@/config/status'

const state = {
  pageData: {
    total: 1,
    per_page: 15,
    current_page: 1,
    last_page: 1
  },
  orderIncreTendency: {},
  orderList: [],
  orderInfo: {}
}

// mutations
const mutations = {
  [types.ORDER_INCRE_TENDENCY] (state, payload) {
    state.orderIncreTendency = payload
  },
  [types.ORDER_LIST] (state, payload) {
    state.orderList = payload.data
    state.pageData.total = Number(payload.total)
    state.pageData.per_page = Number(payload.per_page)
    state.pageData.current_page = Number(payload.current_page)
    state.pageData.last_page = Number(payload.last_page)
  },
  [types.ORDER_INFO] (state, payload) {
    state.orderInfo = payload
  }
}

// actions
const actions = {
  // serverorder/order/Order/orderIncreTendency
  async orderIncreTendency ({ commit }) {
    let getRes = await api('serverorder/order/Order/orderIncreTendency', {})
    SUCCESS_STATUS && commit(types.ORDER_INCRE_TENDENCY, getRes.res)
    return promise(getRes)
  },
  // 获取订单列表
  async orderList ({ commit }, payload) {
    let listRes = await api('serverorder/order/Order/allOrderList', payload)
    commit(types.ORDER_LIST, listRes.res)
  },
  // 获取订单详情
  async orderInfo ({ commit }, payload) {
    let infoRes = await api('serverorder/order/Order/adminOrderInfo', payload)
    commit(types.ORDER_INFO, infoRes.res)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
